package com.pay.controller;

import com.common.common.BaseResponse;
import com.common.common.ResultUtils;
import com.common.controller.AbstractTypedController;
import com.pay.entity.PayInfo;
import com.pay.service.PayServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Random;


@Component
@RestController
@RequestMapping("pay")
@Slf4j
@CrossOrigin
@Tag(name = "支付")
public class PayController extends AbstractTypedController<PayInfo, Integer> {
    @Resource
    PayServiceImpl payService;

    PayController(PayServiceImpl payService ) {
        this.svcContext = payService;
        this.payService = payService;
    }

//    @Resource
//    PayFeignService payFeignService;


    @GetMapping("/creatpaybyoid/{oid}")
    @Operation(summary = "创建 数据实体")
    public BaseResponse<PayInfo> createbyoid(@PathVariable Integer oid ) {
        PayInfo payInfo = new PayInfo();
        // var order = payFeignService.queryById(oid);
        // 生成 Random 对象
        Random random = new Random();
        int number = random.nextInt(10000);
        String url = "http://wechart" + number + ".com";
        payInfo.setUrl(url);
        payInfo.setOrderId(oid);
        payService.create(payInfo);
        return ResultUtils.success(payInfo);
    }
}
